﻿
<?php
// session_start();
	
	if (!isset($_SESSION["taikhoan"]))
	{
		header("Location: ad-dangnhap.php");
	}
	
  include "connect.php";
  $data = array();
  $kq = 0;
    
  function add_person($ma,$ten,$email,$ns,$gt,$tk,$malop,$mk)
  {
	  global $data;
	  
	  $data []= array(
		  'ma' => $ma,
		  'ten'=> $ten,
		  'email' => $email,
		  'ns' => $ns,
		  'gt' => $gt,
		  'tk' => $tk,
		  'malop' => $malop,
		  'mk' => $mk
		  
		  );
	  }
  
	  if ( $_FILES['file']['tmp_name'] )
	  {
		  $dom = DOMDocument::load( $_FILES['file']['tmp_name'] );
		  $rows = $dom->getElementsByTagName( 'Row' );
		  $mssv_row = true;
		  foreach ($rows as $row)
		  {
			  if ( !$mssv_row )
			  {	 
					  $index = 1;
					  $cells = $row->getElementsByTagName( 'Cell' );
					  foreach( $cells as $cell )
					  { 
						  $ind = $cell->getAttribute( 'Index' );
						  if ( $ind != null ) $index = $ind;
						  
						  if ( $index == 1 ) $ma = $cell->nodeValue;
						  if ( $index == 2 ) $ten = $cell->nodeValue;
						  if ( $index == 3 ) $email = $cell->nodeValue;	
						  if ( $index == 4 ) $ns = $cell->nodeValue;
						  if ( $index == 5 ) $gt = $cell->nodeValue;
						  if ( $index == 6 ) $tk = $cell->nodeValue;
						  if ( $index == 7 ) $malop = $cell->nodeValue;
						  if ( $index == 8 ) $mk = $cell->nodeValue;
						  				  
						  $index += 1;
					  }
					  add_person($ma,$ten,$email,$ns,$gt,$tk,$malop,$mk);
			}
			$mssv_row = false;
		}
		$kq = count($data);
  	}
  ?>
  <html>
  <head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>upload file</title>
  </head>
  <body>
  <table>
          <tr><td height="50">&nbsp;</td></tr>
  </table>
  <form name="form1" enctype="multipart/form-data" method="post" action="">
    
           <table width="500" align="center" border="0" style="border:1px solid #0066FF" cellspacing="0" >
									
								  <tr> 
										<td height="30" colspan="2" align="center" bordercolor="#FFFFFF" background="image/bg_header.gif">
											<span style="font-size:24px; color:#FFFFFF; font-weight:bold;">Upload file Sinh Viên</span></td>
								  </tr>
								  
								  <tr><td height="15" colspan="2" bordercolor="#FFFFFF"></td></tr>
									
								  <tr bordercolor="#FFFFFF" align="center"> 
									  <td  height="30" style="font-size:18px" width="200">File Excel:</td>
									  <td align="left"> <input type="file" name="file" size="40">   </td>
								  </tr>
								  
								  
								  <tr><td height="15" colspan="2" bordercolor="#FFFFFF"></td></tr>
								  
								  <tr bordercolor="#FFFFFF">
									  <td  align="center" height="30" colspan="2"> <input type="submit" name="Submit" value="Import"></td>
								 </tr>
								 <tr><td colspan="2" height="20">&nbsp;</td></tr>
								
			</table>
   
  </form>
  
  <?php 
    $q="SV";
  	foreach( $data as $row ) 
	{
  		mysql_query( "insert into `sinh vien` values('".$row["ma"]."','".$row["ten"]."','".$row["email"]."','".$row["ns"]."','".$row["gt"]."','".$row["tk"]."','".$row["malop"]."')");
	    mysql_query( "insert into `tai khoan` values('".$row["tk"]."','".$row["mk"]."','$q')");  
  	} 	
?>
  
  </body>
  </html>
﻿
   
   